package com.happy016.feign;

import com.happy016.pojo.User;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * feign fall back 回退
 * @author Linyb
 * @since 2017/10/10 14:00
 */
@Component
public class UserFeignFallBackFactory implements FallbackFactory<UserFeignClientByFallbackFactory> {

    private final Logger logger = LoggerFactory.getLogger(UserFeignFallBackFactory.class);

    @Override
    public UserFeignClientByFallbackFactory create(Throwable throwable) {
        return new UserFeignClientByFallbackFactory() {
            @Override
            public User findById(Integer id) {
                logger.error("fall back reason :",throwable);
                User user = new User();
                user.setId(id);
                user.setUsername("Hystrix-FallbackFactory");
                return user;
            }
        };
    }
}
